#include "CustomControlPage.h"
#include "ui_CustomControlPage.h"

CustomControlPageWidget::CustomControlPageWidget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);

    m_pCTimeAxis = nullptr;
    m_pLabel = nullptr;
    Init();
}

CustomControlPageWidget::~CustomControlPageWidget()
{
    if(m_pLabel)
    {
        delete m_pLabel;
        m_pLabel = nullptr;
    }

    if(m_pCTimeAxis)
    {
        delete m_pCTimeAxis;
        m_pCTimeAxis = nullptr;
    }

    delete ui;

}

void CustomControlPageWidget::Init()
{
    QVBoxLayout* vboxLayout = new QVBoxLayout(this);

    m_pLabel = new QLabel();
    m_pLabel->setStyleSheet(
        R"(
            QLabel {
               color: #FFFFFF;
               background-color: #000000;
               border:1px solid #00BFFF;
               padding:5px;
               border-radius:5px;
               qproperty-alignment: 'AlignCenter';
               font-size: 20px;
            }
        )"
        );

    vboxLayout->addWidget(m_pLabel);


    m_pCTimeAxis = new CTimeAxis();
    connect(m_pCTimeAxis, &CTimeAxis::TimeChange, this, &CustomControlPageWidget::OnTimeChange);


    vboxLayout->addWidget(m_pCTimeAxis);
}

void CustomControlPageWidget::OnTimeChange(const QString & strCurTime)
{
    if(m_pLabel)
    {
        m_pLabel->setText(strCurTime);
    }
}
